package com.dyx.api.files.controller;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.core.io.FileSystemResource;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


/**
 * Created by Administrator on 2017/7/27 0027.
 */

@RestController
@RequestMapping("/appSide")
public class ControllerByTL extends BaseController {

    @Autowired
    private Environment env;

    @RequestMapping(value="/selectBuyBrands", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/selectBuyBrands" ,notes ="品牌中心-采购品牌-列表")
    @ApiImplicitParam(name = "param", required = true, dataType = "{}")
    public String selectBuyBrands(@RequestBody(required = false) JSONObject param){
        try{
            param.put("userId",getSessionUserLesseeId());
            JSONObject resultData = selectOtherModule(env.getProperty("rest.BrandController"),env.getProperty("rest.BuyBrandController.findAll"),param);
            return resultData.toJSONString();
        }catch (Exception e){
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    @RequestMapping(value="/updateBuyBrands", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/updateBuyBrands" ,notes ="品牌中心-采购品牌-屏蔽取消屏蔽")
    @ApiImplicitParam(name = "param", required = true, dataType = "{\"id\":\"1243\",\"ifShield\":true}")
    public String updateBuyBrands(@RequestBody JSONObject param){
        try{
            JSONObject resultData = selectOtherModule(env.getProperty("rest.BrandController"),env.getProperty("rest.BuyBrandController.modifyBuyBrand"),param);
            return resultData.toJSONString();
        }catch (Exception e){
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

    //获取Tenid信息
    @RequestMapping(value="/selectTenId", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "/selectTenId" ,notes ="查询租户id是否存在并返回")
    public String selectTenId(@RequestBody JSONObject param) {
        try {
            JSONObject resultData = selectOtherModule(env.getProperty("rest.UserController"), env.getProperty("rest.UserController.selectTenId"), param);
            return resultData.toJSONString();
        } catch (Exception e) {
            e.printStackTrace();
            return returnErrorMessage("服务器繁忙,请稍后重试!");
        }
    }

}
